<script>
function updateWidgets() {
    $("img.widget").each(function(i) {
        updateWidget(this);
    });
};

function updateWidget(wid) {
    isDark = $('link[href="/css/theme-dark.css"]').length > 0;
    src = wid.src;
    if (isDark) {
        newsrc = src.replace("-light", "-dark");
    } else {
        newsrc = src.replace("-dark", "-light");
    }
    wid.src = newsrc;
};

var Observer   = window.MutationObserver || window.WebKitMutationObserver;
var myObserver = new Observer(mutationHandler);
var obsConfig  = {attributes: true};

$("head link").each(function() {
    myObserver.observe(this, obsConfig);
});

function mutationHandler(recs) {
    updateWidgets();
};

$( document ).ready(updateWidgets);
</script>

